<?php
include('../../inc/global.inc');
include("../islogin.php");
?>
<?php
if($_POST[act_tj]){
$psw=substr(md5($_POST['admin_psw']),6,18);
mysql_query("insert into admin (admin_cname,admin_psw,admin_name,admin_sys,admin_dj) values ('$_POST[admin_cname]','$psw','$_POST[admin_name]','$_POST[admin_sys]','$_POST[admin_dj]')");
echo "<script>alert('添加成功');location='index.php';</script>";
}
?>
<?php
if($_POST['act_xg']){
$len_psw=strlen($_POST['admin_psw']);
if($len_psw==18){
mysql_query("update admin set admin_cname='$_POST[admin_cname]',admin_name='$_POST[admin_name]',admin_sys='$_POST[admin_sys]',admin_dj='$_POST[admin_dj]' where id='".$_POST['iid']."'");
echo "<script>alert('修改成功');location='index.php';</script>";
}
else
{
$psw=substr(md5($_POST['admin_psw']),6,18);
mysql_query("update admin set admin_cname='$_POST[admin_cname]',admin_name='$_POST[admin_name]',admin_psw='$psw',admin_sys='$_POST[admin_sys]',admin_dj='$_POST[admin_dj]' where id='".$_POST['iid']."'");
echo "<script>alert('修改成功');location='index.php';</script>";
}
}
?>
<HTML>
<HEAD>
<TITLE>Admin</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<LINK href="../css/css.css" rel=stylesheet>
<script type='text/javascript' src="../js/islogin.js" charset="gb2312"></script>
</HEAD>
<BODY>
<center>
  <table width="50%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
    <tr>
      <td height="25" bgcolor="#EEEEF9" style="padding-left:5px;">添加、修改管理员&nbsp;&nbsp;<a href="javascript:history.go(-1)">返回</a></td>
    </tr>
  </table>
<?php
if($_GET[tj]){
?>
  <table width="50%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
  <form method="post" action="index_modify.php" onSubmit="return check()">
    <tr>
      <td height="30" colspan="2" align="center" bgcolor="#8DA8CF">添加管理员信息</td>
    </tr>
    <tr>
      <td width="28%" height="30" align="center" bgcolor="#FFFFFF">用户名</td>
      <td width="72%" align="left" bgcolor="#FFFFFF" style="padding-left:2px;"><input name="admin_cname" type="text" size="18" maxlength="20">
        <font color="red">*</font>6-15 字符</td>
    </tr>
    <tr>
      <td height="30" align="center" bgcolor="#FFFFFF">密码</td>
      <td align="left" bgcolor="#FFFFFF" style="padding-left:2px;"><input name="admin_psw" type="password" size="20" maxlength="50">
      <font color="red">*</font>6-15 字符</td>
    </tr>
    <tr>
      <td height="30" align="center" bgcolor="#FFFFFF">姓名</td>
      <td align="left" bgcolor="#FFFFFF" style="padding-left:2px;"><input name="admin_name" type="text" size="18" maxlength="20">
        <font color="red">*</font></td>
    </tr>
	<tr>
      <td height="30" align="center" bgcolor="#FFFFFF">管理员等级</td>
      <td height="30" align="left" bgcolor="#FFFFFF"><input name="admin_dj" type="radio" value="1" checked>高级&nbsp;<input type="radio" name="admin_dj" value="2">普通</td>
    </tr>
    <tr>
      <td height="30" align="center" bgcolor="#FFFFFF">锁定管理员</td>
      <td height="30" align="left" bgcolor="#FFFFFF"><input name="admin_sys" type="radio" value="1" checked>
        不锁定&nbsp;<input type="radio" name="admin_sys" value="0">
        锁定（锁定管理将不能登陆）</td>
    </tr>
	    <tr>
      <td height="30" colspan="2" align="center" bgcolor="#FFFFFF"><input type="submit" value="提交"></td>
    </tr>
	<input type="hidden" name="act_tj" value="ok">
	</form>
  </table>
  <?php
}
?>
<?php
if($_GET['xg']){
$sql="select * from admin where id=".$_GET['xg_id'];
$rs=mysql_query($sql);
$row=mysql_fetch_array($rs)
?>
  <table width="50%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
  <form method="post" action="index_modify.php">
    <tr>
      <td height="30" colspan="2" align="center" bgcolor="#8DA8CF">修改管理员信息</td>
    </tr>
    <tr>
      <td width="28%" height="30" align="center" bgcolor="#FFFFFF">用户名</td>
      <td width="72%" align="left" bgcolor="#FFFFFF" style="padding-left:2px;"><input name="admin_cname" type="text" value="<?=$row[admin_cname]?>" size="18" maxlength="20"></td>
    </tr>
    <tr>
      <td height="30" align="center" bgcolor="#FFFFFF">密码</td>
      <td align="left" bgcolor="#FFFFFF" style="padding-left:2px;"><input name="admin_psw" type="password" value="<?=$row['admin_psw']?>" size="30" maxlength="50"></td>
    </tr>
    <tr>
      <td height="30" align="center" bgcolor="#FFFFFF">姓名</td>
      <td align="left" bgcolor="#FFFFFF" style="padding-left:2px;"><input name="admin_name" type="text" value="<?=$row['admin_name']?>" size="18" maxlength="20"></td>
    </tr>
	<tr>
      <td height="30" align="center" bgcolor="#FFFFFF">管理员等级</td>
      <td height="30" align="left" bgcolor="#FFFFFF"><input name="admin_dj" type="radio" value="1" <?php if($row[admin_dj]==1){echo "checked";}?>>
        高级&nbsp;
        <input type="radio" name="admin_dj" value="2" <?php if($row[admin_dj]==2){echo "checked";}?>>
        普通</td>
    </tr>
	<tr>
      <td height="30" align="center" bgcolor="#FFFFFF">锁定管理员</td>
      <td height="30" align="left" bgcolor="#FFFFFF"><input type="radio" name="admin_sys" value="1" <?php if($row[admin_sys]==1){echo "checked";}?>>
      不锁定&nbsp;
      <input type="radio" name="admin_sys" value="0" <?php if($row[admin_sys]==0){echo "checked";}?>>
      锁定（锁定管理将不能登陆）</td>
    </tr>
    <tr><input type="hidden" name="act_xg" value="ok">
	<input type="hidden" name="iid" value="<?=$row['id']?>">
      <td height="30" colspan="2" align="center" bgcolor="#FFFFFF"><input type="submit" value="提交"></td>
    </tr>
	</form>
  </table>
<?php
}?>
</center>
</BODY>
</HTML>
<script language="javascript">
function $(id){
return document.getElementById(id);
}
function check(){
if($("admin_cname").value==""){
alert("用户名不能为空");
$("admin_cname").focus();
return false;
}
if($("admin_psw").value.length<6||$("admin_psw").value.length>15){
alert("请输入6-15为密码");
$("admin_psw").focus();
return false;
}
if($("admin_name").value==""){
alert("请输入姓名");
$("admin_name").focus();
return false;
}
}
</script>
